package com.hns.can.safety.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.safety.entity.CommMftCopaEntity;
import com.hns.can.safety.vo.FaultTypeVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 故障设置
 * @author:lan
 * @email:763836737@qq.com
 * @version Revision 2.0.0
 */

@Service
public class FaultTypeService extends CommonService {
    
    @Autowired
    private FillCodeDscValue codeDscValue;
    /**
     * 
     * @param entity
     * @param request
     * @return
     * @throws Exception
     * @author:Lan
     * @email:763836737@qq.com
     * @创建日期:2014-10-29
     * @功能说明： 查询
     */
    @Transactional
    public Pagination searchFaultTypePage(FaultTypeVo vo) throws Exception {
        Pagination page = this.myBatisPage("faultType.searchFaultTypeCount","faultType.searchFaultType",vo,CommMftCopaEntity.class);
        Map<String,String> map = new HashMap<String,String>();
        map.put("corpName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo vo1 = new FillParamsVo("corpId", map);
        codeDscValue.fillInfoValue(page.getData(),new String[]{GlobalConst.CACHE_KEY_SYS_CORP},vo1);
        return page;
    }
    
    
  /**
   * 
   * @param entity
   * @return
   * @author:Lan
   * @email:763836737@qq.com
   * @创建日期:2014-10-29
   * @功能说明：查询数据库是否有相同故障名称
   */
    public int getMftCopaByName(CommMftCopaEntity entity) {
        int count = (Integer) sqlMapDao.selectOne("faultType.getMftCopaByName", entity);
        return count;
    }
    
    /**
     * 
     * @param entity
     * @return
     * @author:Lan
     * @email:763836737@qq.com
     * @创建日期:2014-10-29
     * @功能说明：查询数据库是否有相同故障编码
     */
    public int getMftCopaByCode(CommMftCopaEntity entity) {
        int count = (Integer) sqlMapDao.selectOne("faultType.getMftCopaByCode", entity);
        return count;
    }
    
    /**
     * 
     * @param entity
     * @author:Lan
     * @email:763836737@qq.com
     * @创建日期:2014-10-29
     * @功能说明：新增
     */
    @Transactional
    public void addFaultType(CommMftCopaEntity entity) {
        commonEntityDao.save(entity);
    }
    /**
     * 
     * @param entity
     * @author:Lan
     * @email:763836737@qq.com
     * @创建日期:2014-10-29
     * @功能说明：修改
     */
    @Transactional
    public void editeFaultType(CommMftCopaEntity entity) {
        //sqlMapDao.update("faultType.updateCommMftCopa",entity);
    }
    
   /**
    * 
    * @param mftTypeCode
    * @return
    * @author:Lan
    * @email:763836737@qq.com
    * @创建日期:2014-10-29
    * @功能说明： 根据ID查询
    */
    @SuppressWarnings("unchecked")
    @Transactional
    public  List<CommMftCopaEntity> getFaultTypeById(String rowidstr){
        List<CommMftCopaEntity>  entity = PubUtil.convertListMapToObject(sqlMapDao.selectList("faultType.searchFaultTypeByRowId",rowidstr), CommMftCopaEntity.class);
        return entity;
    }
    
    /**
     *     
     * @param entity
     * @author:Lan
     * @email:763836737@qq.com
     * @创建日期:2014-10-29
     * @功能说明：删除
     */
    @Transactional
    public void delFaultType(CommMftCopaEntity entity) {
        CommMftCopaEntity delEntity = commonEntityDao.find(entity.getMftTypeCode(), CommMftCopaEntity.class);
        commonEntityDao.delete(delEntity);
    }
    
    
    /**
     * 
     * @param vo
     * @return
     * @throws QueryExprException
     * @author:Lan
     * @email:763836737@qq.com
     * @创建日期:2014-10-29
     * @功能说明：导出
     */
    @SuppressWarnings("unchecked")
    @Transactional
    public List<BaseEntity> exportFaultType(FaultTypeVo vo) throws Exception{
        List<BaseEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("faultType.searchFaultType", vo), CommMftCopaEntity.class);
        Map<String,String> mapTmp = new HashMap<String,String>();
        mapTmp.put("mftClCode", "MFTC0000");
        codeDscValue.fillCodeDscValue(list, mapTmp);
        return list;
    }
    
    /**
     * 
     * @param entity
     * @return
     * @author:Lan
     * @email:763836737@qq.com
     * @创建日期:2014-10-29
     * @功能说明：查询数据库是否有相同故障编码
     */
    public int getMftCopaByCodeAndName(CommMftCopaEntity entity) {
        int count = (Integer) sqlMapDao.selectOne("faultType.getMftCopaByCodeAndName", entity);
        return count;
    }
}